package com.mars.weixin.web.boss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.mars.base.common.exception.AppException;
import com.mars.base.common.utils.web.ResponseResult;
import com.mars.base.web.BaseController;
import com.mars.base.web.model.DataGrid;
import com.mars.boss.weixin.entity.WxText;
import com.mars.boss.weixin.service.WxTextService;

@RestController
@RequestMapping("/weixin/text")
public class WxTextController extends BaseController {

	@Autowired
	private WxTextService service;

	@PostMapping(value = "/add")
	public Object add(WxText entity) {
		try {
			this.service.insert(entity);
		} catch (AppException e) {
			return ResponseResult.addFailed();
		}
		return ResponseResult.addOk();
	}

	@GetMapping(value = "/delete/{ids}")
	public Object delete(@PathVariable String ids) {
		try {
			this.service.deleteByIds(ids);
		} catch (AppException e) {
			return ResponseResult.deleteFailed();
		}
		return ResponseResult.deleteOk();
	}

	@PostMapping(value = "/update")
	public Object update(WxText entity) {
		try {
			this.service.update(entity);
		} catch (AppException e) {
			return ResponseResult.updateFailed();
		}
		return ResponseResult.updateOk();
	}

	@GetMapping(value = "/get/{id}")
	public WxText get(@PathVariable Long id) {
		return this.service.selectById(id);
	}

	@GetMapping(value = "/list")
	public Object list(WxText entity) {
		try {
			PageInfo<WxText> selectPage = this.service.selectPage(getPageParam(), entity);
			DataGrid<WxText> dg = new DataGrid<WxText>() ;
			dg.setRows(selectPage.getList());
			dg.setTotal(selectPage.getTotal());
			return dg ;
		} catch (AppException e) {
			return ResponseResult.loadFailed();
		}
	}
	
	@GetMapping(value = "/combobox")
	public Object combobox(WxText entity) {
		return this.service.combobox() ;
	}

}
